package cn.com.headfree.depterprela.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gta.edu.sdk.base.service.impl.BaseServiceImpl;
import com.gta.edu.sdk.common.dto.Page;

import cn.com.headfree.depterprela.dao.IDeptErpRelaDao;
import cn.com.headfree.depterprela.service.IDeptErpRelaService;
import cn.com.headfree.entity.TBusinessWorkflowBind;
import cn.com.headfree.entity.TDeptEmpRela;
import cn.com.headfree.entity.TIscRole;
import cn.com.headfree.entity.UserDeptERpRelaMsg;

/**
 * @Title  DeptErpRelaServiceImpl.java
 * @Package cn.com.headfree.depterprela.service.impl
 * @Description 用户部门Erp关联信息serviceImpl
 * @author yangwang
 * @date  2020年7月3日 下午5:08:11
 */
@Service("deptErpRelaService")
public class DeptErpRelaServiceImpl extends BaseServiceImpl<TDeptEmpRela> implements IDeptErpRelaService {
	private static final Logger LOG = LogManager.getLogger(DeptErpRelaServiceImpl.class);

	@Autowired
	private IDeptErpRelaDao deptErpRelaDao;

	/**
	 * 获取部门下所有人员
	 * @param userMsg
	 *  */
	@Override
	public void getUsersOfDeptPage(Page<UserDeptERpRelaMsg> page,UserDeptERpRelaMsg userMsg) {
		deptErpRelaDao.getUsersOfDeptPage(page, userMsg);
	}


	/**
	 * 获取人员erp编码信息
	 * @param userIds
	 * @return List<UserDeptERpRelaMsg>
	 *  */
	@Override
	public List<UserDeptERpRelaMsg> getErpNoByUserIds(String userIds){
		return deptErpRelaDao.getErpNoByUserIds(userIds);
	}

	/**
	 * 新增角色信息
	 * @param role
	 *  */
	@Transactional
	@Override
	public void saveIscRole(TIscRole role) {
		if((null != role)&&(StringUtils.isNotBlank(role.getId()))) {
			TIscRole oldRole = deptErpRelaDao.getIscRoleById(role.getId());
			if((null != oldRole)&&(StringUtils.isNotBlank(oldRole.getId()))) {//更新
				deptErpRelaDao.editIscRole(oldRole);
			}else {//新增
				deptErpRelaDao.insertIscRole(role);
			}
		}
	}

	/**
	 * 保存角色信息
	 * @param roleList
	 * @throws SQLException
	 *  */
	@Transactional
	@Override
	public void saveIscRole(List<TIscRole> roleList) throws SQLException{
		if((null != roleList)&&(0 < roleList.size())) {
			for(TIscRole r:roleList) {
				this.saveIscRole(r);
			}
		}
	}

	/**
	 *根据id获取角色信息
	 * @param id
	 * @return TIscRole
	 *  */
	@Override
	public TIscRole getIscRoleById(String id) {
		return deptErpRelaDao.getIscRoleById(id);
	}

	/**
	 *根据code获取角色信息
	 * @param code
	 * @return List<TIscRole>
	 *  */
	@Override
	public List<TIscRole> getIscRoleByCode(String code){
		return deptErpRelaDao.getIscRoleByCode(code);
	}

	/**
	 * 获取角色信息
	 * @param
	 *  */
	@Override
	public List<TIscRole> getIscRoleList(TIscRole role){
		return deptErpRelaDao.getIscRoleList(role);
	}


	/**
	 * 获取角色信息
	 * @param bind
	 * @return TBusinessWorkflowBind
	 *  */
	@Override
	public TBusinessWorkflowBind getBusinessBind(TBusinessWorkflowBind bind) {
		return deptErpRelaDao.getBusinessBind(bind);
	}

	@Override
	public List<TDeptEmpRela> getOrgIdByErpNo(String erpNo) {
		return deptErpRelaDao.getOrgIdByErpNo(erpNo);
	}

	@Override
	public List<TDeptEmpRela> getDeptInfoByErpNo(String erpNo) {
		return deptErpRelaDao.getDeptInfoByErpNo(erpNo);
	}

	@Override
	public List<TDeptEmpRela> getErpNoByOrgId(String orgId) {
		return deptErpRelaDao.getErpNoByOrgId(orgId);
	}

	@Override
	public List<TDeptEmpRela> getFullDeptPathByErpNo(String erpNo) {
		return deptErpRelaDao.getFullDeptPathByErpNo(erpNo);
	}


	@Override
	public TDeptEmpRela getDeptInfoByDeptId(String deptId) {
		return deptErpRelaDao.getDeptInfoByDeptId(deptId);
	}

}
